package com.isfto.service.impl;



import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.isfto.dao.BeforeFlightChangeEnterAanOutDao;
import com.isfto.entity.tablepojo.FlightChange;
import com.isfto.entity.tablepojo.PageBean;
import com.isfto.entity.tablepojo.Tickets;
import com.isfto.entity.tablepojo.UpdateFilghtStatus;
import com.isfto.service.BeforeFlightChangeEnterAndOutService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class BeforeFlightChangeEnterAndOutServiceImpl implements BeforeFlightChangeEnterAndOutService {
   @Resource
    BeforeFlightChangeEnterAanOutDao beforeFlightChangeEnterDao;

    @Override
    public int beforeSaveInfo(FlightChange flightChange) {
        return beforeFlightChangeEnterDao.beforeSaveInfo(flightChange);
    }

    @Override
    public int beforeSaveInfoOut(FlightChange flightChange) {
        return beforeFlightChangeEnterDao.beforeSaveInfoOut(flightChange);
    }

    @Override
    public int deleteInfo(String cfno, String startapcd, String endapcd) {
        return beforeFlightChangeEnterDao.deleteInfo(cfno, startapcd, endapcd);
    }

    @Override
    public int deleteInfoOut(String cfno, String startapcd, String endapcd) {
        return beforeFlightChangeEnterDao.deleteInfoOut(cfno, startapcd, endapcd);
    }

    @Override
    public PageBean beforeInfoEnter(String cfno, String startapcd, String endapcd) {
        List<FlightChange> flightChanges = beforeFlightChangeEnterDao.beforeInfoEnter(cfno,startapcd,endapcd);
        PageBean pageBean=new PageBean();
        pageBean.setRecords(flightChanges);
        return pageBean;
    }

    @Override
    public PageBean beforeInfoOut(String cfno, String startapcd, String endapcd) {
        List<FlightChange> flightChanges = beforeFlightChangeEnterDao.beforeInfoOut(cfno, startapcd, endapcd);
        PageBean pageBean=new PageBean();
        pageBean.setRecords(flightChanges);
        return pageBean;
    }

    @Override
    public PageBean audittickets(Integer pageno, Integer pageSize, Integer status) {
        PageHelper.startPage( pageno,pageSize );
        Page<FlightChange> page1 = beforeFlightChangeEnterDao.pageQuery(status);
        Page<FlightChange> page2 = beforeFlightChangeEnterDao.pageQuery1(status);
        PageBean pageBean = new PageBean();
        long total = page1.getTotal()+page2.getTotal();
        List<FlightChange> list = new ArrayList<>();
        list.addAll(page2.getResult() );
        list.addAll( page1.getResult() );
        pageBean.setRecords( list );
        pageBean.setTotal( (int) total );
        return pageBean;
    }

    @Override
    public Boolean update(UpdateFilghtStatus updateFilghtStatus) {
        Boolean b = beforeFlightChangeEnterDao.update( updateFilghtStatus );
        if (b==false){
            Boolean b1 = beforeFlightChangeEnterDao.update1( updateFilghtStatus );
            b=b1;
        }
        return b;
    }


}
